package com.caiyouxi.app.service.impl;

import com.caiyouxi.app.mapper.AppInfoMapper;
import com.caiyouxi.app.model.AppInfoBean;
import com.caiyouxi.app.service.AppInfoSerivces;
import com.caiyouxi.common.bean.QueryParams;
import com.caiyouxi.common.bean.ResData;
import com.caiyouxi.common.cache.RedisService;
import com.caiyouxi.common.service.BaseService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class AppInfoServicesImpl extends BaseService implements AppInfoSerivces{
    @Autowired
    private AppInfoMapper mapper;
    @Autowired
    private RedisService redisService;

    private Logger logger = Logger.getLogger(AppInfoServicesImpl.class);

    @Override
    public ResData deleteByPrimaryKey(AppInfoBean bean) {
        return success(mapper.deleteByPrimaryKey(bean.getId()));
    }

    @Override
    public ResData add_app(AppInfoBean bean) {

        bean.setCreate_time(new Date());
        return success(mapper.add_app(bean));
    }

    @Override
    public ResData update_app(AppInfoBean bean) {

        bean.setUpdate_time(new Date());
        return success(mapper.update_app(bean));
    }

    @Override
    public ResData get_app_by_id(AppInfoBean bean) {
        return success(mapper.get_app_by_id(bean.getId()));
    }

    /**
     * 分页查询
     * */
    @Override
    public ResData select_app_list(AppInfoBean bean) {
        QueryParams page_list = new QueryParams();
        Integer pageSize = Integer.parseInt(redisService.get("sys.pagesize").toString());
        if(bean.getPage_size() == 0){
            bean.setPage_size(pageSize);
        }
        page_list.setPage_size(bean.getPage_size());
        page_list.setList(mapper.select_appinfo_list(bean));
        page_list.setTotal(mapper.get_appinfo_count(bean));
        page_list.setPage(bean.getPage());
        return success(page_list);
    }
}
